package server

// HandlerFunc 方法签名
type HandlerFunc func(*Context)

// router 路由类
type router struct {
	handlers map[string]HandlerFunc // 路由map
}
// newRouter 实例化一个路由
func newRouter() *router {
	return &router{
		handlers: make(map[string]HandlerFunc)
	}
}
// addRoute 添加路由规则
func (r *router) addRoute(method string, pattern string, handlerFunc HandlerFunc) {
	key := method + "-" + pattern
	r.handlers[key] = handlerFunc
}
// matchRoute 匹配路由执行处理函数
func (r *router) matchRoute(c *Context)  {
	key:=c.Method+"-"+c.Path
	if handlerFunc, ok := r.handlers[key]; ok {
		handlerFunc(c)
	} else {
		c.String(http.StatusNotFound, "404 NOT FOUND: %s\n", c.Path)
	}
}
